package bpm.dao.impl.deptagenda;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import org.springframework.jdbc.core.RowMapper;

import bpm.domain.deptagenda.AgendaDept;
import bpm.domain.deptagenda.AgendaUser;
/**
 * 
 * @author wanglong635@126.com
 *
 */
public class AgendaUserMapper implements RowMapper {
	private boolean contain;
	
	public AgendaUserMapper (boolean contain){
		this.contain = contain;
	}
	
	public Object mapRow(ResultSet rs, int i) throws SQLException {
		AgendaUser user = new AgendaUser();
		
		user.setUserId(rs.getString("USERID"));
		user.setUserName(rs.getString("USERNAME"));
		
		if(contain){
			Timestamp userCtime = rs.getTimestamp("USERCTIME");
			if(userCtime!=null)
				user.setUserCtime(String.format("%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS", userCtime));
				
			Timestamp userUtime = rs.getTimestamp("USERUTIME");
			if(userUtime!=null)
				user.setUserUtime(String.format("%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS", userUtime));
			user.setUserIndex(rs.getString("USERINDEX"));
		}
		
		
		user.setUserMain(rs.getString("USERMAIN"));
		AgendaDept dept = new AgendaDept();
		dept.setDeptCode(rs.getString("DEPTCODE"));
		dept.setDeptName(rs.getString("DEPTNAME"));
		
		dept.setDeptParent(new AgendaDept(rs.getString("DEPTPCODE"),rs.getString("DEPTPNAME")));
		user.setAgendaDept(dept);
		user.setUserIndex(rs.getString("USERINDEX"));
		
		return user;
	}

}
